
//ajax 传参
function load(){
	var xmlhttp;
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp = new XMLHttpRequest();
	} else {// code for IE6, IE5
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			//json数组的解析
			var list = xmlhttp.responseText;
			
		}
	}
	xmlhttp.open("GET", "lilteratureservlet", true);
	xmlhttp.send();
}

 function checkFlag(){
	var cparent =document.getElementById("container");
 	var ccontent=getChildElement(cparent,"box");
 	var lastContentHeight=ccontent[ccontent.length-1].offsetTop;
	//console.log(lastContentHeight);
	var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
	//console.log(scrollTop);
	var pageHeight=document.documentElement.clientHeight||document.body.clientHeight;
	console.log(lastContentHeight+":"+scrollTop+":"+pageHeight);
	if(lastContentHeight<scrollTop+pageHeight)
	{
		return true;
	}

}


function imglocation(parent,content){
//将parent下有的content全部取出
var cparent=document.getElementById(parent);

var ccontent=getChildElement(cparent,content);//content = box

console.log(ccontent.length);

var imgwidth =ccontent[0].offsetWidth;

var num=Math.floor(document.documentElement.clientWidth/imgwidth);//取整的列数
//console.log(num);

	cparent.style.cssText='width:'+imgwidth*num+'px;margin:0px auto';//设置宽度

var boxHeightArr=[];
	for(var i=0;i<ccontent.length;i++)
	{
		if(i<num)
		{
			boxHeightArr[i]=ccontent[i].offsetHeight;
			//console.log(boxHeightArr[i]);
		}else {
			var minHeight=Math.min.apply(null, boxHeightArr);
			console.log(minHeight);
			var minIndex=getminheightLocation(boxHeightArr,minHeight);

			ccontent[i].style.position="absolute";
			ccontent[i].style.top=minHeight+"px";
			ccontent[i].style.left =ccontent[minIndex].offsetLeft+"px";
			boxHeightArr[minIndex]=boxHeightArr[minIndex]+ccontent[i].offsetHeight;
		}
	}
}

function getminheightLocation(boxHeightArr,minHeight)
{
	for(var i in boxHeightArr)
	{
		if(boxHeightArr[i]==minHeight)
		{
			return i;
		}
	}
}




function getChildElement(parent,content){
	var contentArr= new Array();
	var allcontent=parent.getElementsByTagName('*');
	for(var i=0;i<allcontent.length;i++)
	{
		if(allcontent[i].className==content)
		{
			contentArr.push(allcontent[i]);
		}
	}
	return contentArr;
}

